package edu.whu.rose.clock.ssql.graphquery;

public class GraphQueryAnswer {

	private int size;
	
	private double[] scores;
	private int[] graphs;
	private int[][] vertexGroups;
	
	public GraphQueryAnswer(int capacity) {
		this.scores = new double[capacity];
		this.graphs = new int[capacity];
		this.vertexGroups = new int[capacity][];
	}
	
	public void add(double score, int graph, int[] vertexes) {
		int low = 0;
		int mid = 0;
		int top = size - 1;
		
		while (low <= top) {
			mid = (low + top) / 2;
			if (score < scores[mid]) {
				top = mid - 1;
			}
			else if (score > scores[mid]) {
				low = mid + 1;
			}
			else {
				for (int i = size; i > mid; i--) {
					scores[i] = scores[i - 1];
					graphs[i] = graphs[i - 1];
					vertexGroups[i] = vertexGroups[i - 1];
				}
				scores[mid] = score;
				graphs[mid] = graph;
				vertexGroups[mid] = vertexes;
				size++;
				return;
			}
		}
		
		for (int i = size; i > low; i--) {
			scores[i] = scores[i - 1];
			graphs[i] = graphs[i - 1];
			vertexGroups[i] = vertexGroups[i - 1];
		}
		scores[low] = score;
		graphs[low] = graph;
		vertexGroups[low] = vertexes;
		size++;
	}
	
	public double getScore(int index) {
		return scores[index];
	}
	
	public int getGraph(int index) {
		return graphs[index];
	}
	
	public int getVertexGroupSize(int index) {
		return vertexGroups[index].length;
	}
	
	public int getVertex(int index1, int index2) {
		return vertexGroups[index1][index2];
	}
	
	public int getSize() {
		return size;
	}
	
}
